﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using KPIS.DBM;
using KPIS.GERP.SECURITY.MODEL;

namespace KPIS.GERP.SECURITY.DAL
{
    public class HrmPositionDAL
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public HrmPositionDAL()
        {

        }
        public DataTable GetFull(Nullable<int> emp_type_seq)
        {
            string strSQL;
            
            DataTable dtb = null;

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@record_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@emp_type_seq", emp_type_seq);

                strSQL = "select p.pos_seq, p.pos_ref, p.pos_name"
                    + ", concat(p.pos_ref, ' : ', p.pos_name) as pos_text"

                    + " from hrm_mp_positions p"
                    + " where p.record_status <> @record_status"
                    + (emp_type_seq != null ? " and p.emp_type_seq = @emp_type_seq" : "")
                    + " order by cast(p.pos_ref as UNSIGNED)";

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }

            return dtb;
        }
    }
}
